package b1.scenes.home.picpane
{
	import b1.controls.basic.BasicMessage;
	import b1.net.*;
	import b1.players.*;
	import b1.scenes.*;
	import b1.scenes.home.*;
	import b1.utils.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.ColorMatrixFilter;
	import flash.ui.Mouse;

	public class AnimalIcon extends Sprite
	{
		public var animalId:int;
		private var tip:BasicMessage;
		private var smallAnimalIconBgr:Sprite 
		
		public function AnimalIcon(animalId:int)
		{
			super();
			this.animalId = animalId;
			var SmallAnimalIconBgr:Class = ResourceHelper.getInstance().getClassByName("SmallAnimalIconBgr");
			smallAnimalIconBgr = new SmallAnimalIconBgr();
			addChild(smallAnimalIconBgr);
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[animalId];
			var SmallAnimalImage:Class = ResourceHelper.getInstance().getClassByName("SmallAnimal" + animalInfo.animalIndex);
			var smallAnimalIcon:Sprite = new SmallAnimalImage();
			smallAnimalIcon.x = 2;
			smallAnimalIcon.height = 40;
			smallAnimalIcon.scaleX = smallAnimalIcon.scaleY;
			addChild(smallAnimalIcon);
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			this.addEventListener(MouseEvent.CLICK, onMouseClick);
		}
		
		private function onMouseClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().mouseDisableFlag && !SceneContainer.getInstance().checkOnlyMousePosition(event.currentTarget))
				return;
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[animalId];
			if (animalInfo.ownerId == PlayerInfoHelper.getInstance().userId)
			{
				var home:Home = SceneContainer.getInstance().currentScene as Home;
				home.switchLiveId(animalInfo.liveId);
			}
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			this.filters = [new ColorMatrixFilter(BFont.brightFilter)];
			
			var string:String = "追踪动物";
			tip = new BasicMessage(string.length * 18, 25, string);
			tip.x = (smallAnimalIconBgr.width - tip.width) / 2;
			tip.y = smallAnimalIconBgr.height + 5;
			addChild(tip);
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			this.filters = null;
			
			if (null !=  tip && null != tip.parent)
        	{
        		tip.parent.removeChild(tip);
        	}
		}
	}
}